package com.hy.domain;

import java.util.List;

import javax.persistence.ManyToOne;
import javax.persistence.TypedQuery;
import javax.validation.constraints.Size;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Hotel {

    @Size(min = 2)
    private String name;

    private String image;

    private String region;

    private String payment;

    private String address;

    private String nearby;

    private String price;

    private String preferential;

    private String phone;

    @Size(max = 40000)
    private String infomation;

    @Size(max = 40000)
    private String room;

    @Size(max = 40000)
    private String meeting;

    @Size(max = 40000)
    private String restaurant;

    @ManyToOne
    private HotelLevel hotelLevel;

    private Integer sort;

    @ManyToOne
    private City city;
    
    private String keywords;
    
	private String description;

    public static List<com.hy.domain.Hotel> getReverseHotel(int first, int max) {
        List<Hotel> list = null;
        try {
            TypedQuery<Hotel> query = entityManager().createQuery("from Hotel order by sort asc", Hotel.class);
            query.setFirstResult(first).setMaxResults(max);
            list = query.getResultList();
        } catch (Exception e) {
        }
        return list;
    }
    
    public static List<Hotel> getSortEntitiesCity(City city, int first, int maxResult) {
    	 List<Hotel> list = null;
         try {
             TypedQuery<Hotel> query = entityManager().createQuery("from Hotel where city = :city order by sort asc", Hotel.class);
             query.setParameter("city", city);
             query.setFirstResult(first).setMaxResults(maxResult);
             list = query.getResultList();
         } catch (Exception e) {
         }
         return list;
    }
    
    public Hotel prev() {
    	try {
    		return entityManager.createQuery("from Hotel where id < :id order by id desc", Hotel.class).setParameter("id", this.getId()).setMaxResults(1).getSingleResult();
		} catch (Exception e) {
			return null;
		}
    }
    
    public Hotel next() {
    	try {
    		return entityManager.createQuery("from Hotel where id > :id order by id asc", Hotel.class).setParameter("id", this.getId()).setMaxResults(1).getSingleResult();
		} catch (Exception e) {
			return null;
		}
    }
}
